package merchants.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import merchants.service.IMerchantsService;
import merchants.service.impl.MerchantsServiceImpl;
import merchants.vo.CreateMerchantsRequest;
import merchants.vo.PassTemplate;
import merchants.vo.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *商户服务controller
 */
@Slf4j
@RestController
@RequestMapping("/merchants")
public class MerchantsCtl {

    //商户服务接口
    private final IMerchantsService iMerchantsService;

    @Autowired
    public MerchantsCtl(IMerchantsService iMerchantsService){
        this.iMerchantsService = iMerchantsService;
    }

    @ResponseBody
    @PostMapping("/create")
    //创建商品
    public Response createMerchants(@RequestBody CreateMerchantsRequest request){
        log.info("createMerchants:{}", JSON.toJSONString(request));
        return iMerchantsService.createMerchants(request);
    }

    @ResponseBody
    @GetMapping("/{id}")
    //根据id构造商户信息
    public Response buildMerchantsInfo(@PathVariable Integer id){
        log.info("buildMerchantsInfo:{}",id);
        return iMerchantsService.buildMerchantsInfoById(id);
    }

    @ResponseBody
    @RequestMapping("/drop")
    //投放优惠券
    public Response dropPassTemplate(@RequestBody PassTemplate passTemplate){

        log.info("dropPassTemplate:{}",passTemplate);
        return iMerchantsService.dropPassTemplate(passTemplate);
    }
}
